package com.promote.test;

/**
 * @ClassName Singleton
 * Description 双重校验锁实现对象单例
 * @Author LiZiHao
 * Date 2022/8/9 14:17
 * @Version 1.0
 **/
public class Singleton {

    private volatile static Singleton uniqueInstance;

    private Singleton() {

    }

    public static Singleton getUniqueInstance() {

        //先判断对象是否已经实例过，没有实例过才进去加锁代码
        if (uniqueInstance == null) {

            //类对象加锁
            synchronized (Singleton.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new Singleton();
                }
            }
        }
        return uniqueInstance;
    }

    public static void operator(StringBuffer x,StringBuffer y) {
        x.append(y);
        y=x;
    }

    public static void main(String[] args) {
        StringBuffer a = new StringBuffer("A");
        StringBuffer b = new StringBuffer("B");

        operator(a,b);
        System.out.println(a+""+b);
    }
}
